import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
import TableControls from '#cpt/temp/TableControls'
import Confirm from '#cpt/temp/Confirm'
import Controls from '#cpt/temp/Controls'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const EmpowerModal		= $Lazy.state(()=>import('./empower-modal'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data: [],
		pag: {},
	}
	
	open = (uuid) => {
		this.uuid = uuid
		this.modal.open()
		this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this, 'doc-file-share-log/shareList',{param:{uuid:this.uuid}})
	
	// 表单
	cols = () => {
		const colsArr = [
			{ title: '共享人',		dataIndex: 'real_name', 	...$fn.table.name },
			{ title: '共享时间', 	dataIndex: 'created_at', 	...$fn.table.time },
			{ title: '共享给', 		dataIndex: 'shareTo', 		width:200,		render: text => $fn.hasArray(text) && text.join('、') },
			{ title: '共享权限', 	dataIndex: 'share_perms', 	width:180,		render: text => $fn.hasArray(text) && text.join('、')	 }
		]
		if(this.props.isPower){
			return [...colsArr,TableControls.controls.call(this,{ width: 150 })]
			
		}else {
			return colsArr
		}
	}
	
	table_controls = (text,row) => {
		return [
			Confirm.call(this, '删除记录', 'doc-file-share-log/cancel',{query:{uuid:row.uuid}}),
			Controls.click.call(this, '权限设置', ()=> this.empowerModal.open([row],true) ),
		]
	}
	
	render(){
		return (
			<>
				{TableModal.call(this,{ title: '共享记录', labelWidth:'s7', width:'80%', height:'70%',noSubmit:true,noCancel:true,close:()=>this.props.onRefresh()})}
				{/* 授权 */}
				<EmpowerModal onRef={ref=>this.empowerModal=ref} onRefresh={this.fetch} />
			</>
		)

	}
}

export default Index